package com.gzdh.tang.dishrecognition.controller;

import com.gzdh.tang.comm.vo.Result;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.wechat.pay.java.service.refund.RefundService;
import com.wechat.pay.java.service.refund.model.AmountReq;
import com.wechat.pay.java.service.refund.model.CreateRequest;
import com.wechat.pay.java.service.refund.model.Refund;
import com.wechat.pay.java.service.refund.model.Status;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("drTest")
public class DrTestController {
    /**
     * 商户号
     */
    public static String merchantId = "1630436051";
    /**
     * 商户API私钥路径
     */
    public static String privateKeyPath = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZiwGYUiRr/D6xdvdSc1fUe78mDT0DqOO7NC1pkaQmZThC/ZMjmbp1324BIXXATmY02MqUuKOy5RpSDyZpqetq65dtEjef1G4PtjrZA62ZtaUG/fqyhwbX+jMWLlXv2R/i72aDb3mhgoP8efXQwNGn6BNGyob/L74v1qO+UPjfDLTXYoy9Gte/J3i1mlbaxKdEjBq3h+lNdlWKYrLK+Rp+gPSQhcGcNSG5C5T7c+X9+HpSzJBv0uzxdKQTWi/nAA877WVcZdopWQQWsaCwG8yjws+vaFsjAZujtvPTV6VIUaap29EU+AzOv7jQRMFsAOzNy+ChoI/yrvkmbOdnUKNNAgMBAAECggEAbOfrJ39P3oOMOzmsfSljOeutePY9qlxdjbWEWopf3BzmOptJkxP9xc7R+lzu3xQglKpHWIbK5N9O+u+8sj8vrPo+d4scL7agVttKwKPXv9CwyjxRyhhQ88S82Ijf2tAe53QkJP6krJdzTe0cg6JUEzPamqD/TjdvhfF1Teyperer/C8Srb2SKacOCU1IFlihApH0XaoyJzHHHG8NROk77PpMVH5IFJcyfpVeLibdMqgi0WfAd+xGc+IrQjQHVE3eJ9NRXYQXxDyzSRdkTrb43wU+85vyl80QtuPDGI3HHDH3wy4a1VdhhRDyJGPeNlwLna1C1XOzM3mndhInmHZ2XQKBgQD7UwqrGUDiSsh/FgFtXlwiCc0/pyHraaQxLIYOLJ9WDQL4dL+RPk0xT61OBsnh83BilRf0ft6dByQSajeEbIdl3dwCWIroAXIvRwVEp48i45+7l7m6yCg7HhdlrzSazJKZZplku7RFOICg/VF1s25vLk5CsACcPEo0Cenjx2G8lwKBgQDdlxPDu83Ji/z5ouE5i4JARm8utl206GrO2tRJ43ydm4IULnr5T8vnOMAgFhM5pFIqEMDeRFwb6qc3nztEiMevItVp2AATsn+A3Pq+IOpMlf5X6j9hlXVJjRI3cUaVxS9fXqnpLGO5odJ0NK/4FOhmJ5BG8hC+Ryiwe6tNYxJHuwKBgQDCkJdBvlss1RhCypZwRQyujUgIbysjRLWIHB/r+T+hLpGOJ1Pm7YR1GGnibf78nanzp9jTvyQ4DL8wQmqYaiyoAAnDBykCU5xCXYkGjXGSYQXYBK4Um8AJhFI4tlrTPGyBtZwrD+WPcR6jg3j81dw41nBf0EGoskP/5Wzcmg5gIQKBgHy0EwlqXYt5XqrWgU2zN2AYw2VUeDPhQIqdGC9k+LJx26ij58z6nVPI2ka0Zalg0mSd/QyZCAUl72kcEWymVUo4nkXsq05qe9r3gZ0SRQlIuFSdnYG7bMAxxfixpPmQePKBAboZox3K9fcz13wTuB4VUdq7S7Tpsvpu/p6UjKsVAoGBAMt6jOaCBCmt3eKyQnmVtTUlLSQOnp+JYb3T4KZNHCA2Lv9A2ns6u8kL2NVy51KZORSN8FV49QBO4MOZ1n6Us1x9IrMMkKsx9k56bBc3lDGXUdZbsak9pvFJW7un/HfHbVA5OzD0NUoVbOQCK42FLTmP7ds4MkQ2m4Otwgz2Fnyt";
    /**
     * 商户证书序列号
     */
    public static String merchantSerialNumber = "653630F4A14BABBB2B6B40D76C834F9AB0C9D5AA";
    /**
     * 商户APIV3密钥
     */
    public static String apiV3Key = "dajieerjielikailizuo605805001501";
    /**
     * 商户公钥
     */
    public static String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsARBUgwhbyiMPJybAhQDSIa4iqMC5glbRp7F3O2oydJz5P9EUomceTkJ2d687LXoMhGuyIeB/KtZmXzvOHEd4fJ3HqVk0H5iIrVM6N0czn4F3Od48KYqeRJL8uUbeOonp23ZXOIETZOu+J/PJTBW8BDSbcX646DVPDlDHGPcgHkZiUp2bk2PxdUTiv+izSUE4W8JI3lndHINreCSeEJfXtXosDkJHH6afoLKlvbjQBE76k6PFjH7r7GTJTuZk9iw+dSbv+7OyuTS/k0qaTt7d9W2ltyaa6YvCIPeaFHOKWX5Up+gVGRmaczv71zG+If/QxLK2ZpWApeWrjPYUnvOYQIDAQAB";
    /**
     * 商户公钥ID
     */
    public static String publicKeyId = "PUB_KEY_ID_0114514832022025061700452360000200";

    @GetMapping("test")
    public Result<Object> test() {
        Result<Object> result = new Result<>();

        Config config = new RSAPublicKeyConfig.Builder()
                .merchantId(merchantId)
                .privateKey(privateKeyPath)
                .publicKey(publicKey)
                .publicKeyId(publicKeyId)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3Key)
                .build();


        RefundService service = new RefundService.Builder().config(config).build();
        CreateRequest createRequest = new CreateRequest();

        AmountReq amountReq = new AmountReq();
        amountReq.setRefund(2L);//【退款金额】 退款金额，单位为分，只能为整数，不能超过原订单支付金额。
        amountReq.setTotal(2L);//【原订单金额】 原支付交易的订单总金额，单位为分，只能为整数。
        amountReq.setCurrency("CNY");//退款币种】 符合ISO 4217标准的三位字母代码，目前只支持人民币：CNY。
        createRequest.setAmount(amountReq);

//        createRequest.setSubMchid("1580836091");
        createRequest.setOutTradeNo("WXZF1511531899680694560522240001");//【商户订单号】 原支付交易对应的商户订单号，与transaction_id二选一
        createRequest.setOutRefundNo("WXTK1511531899680694560522240002");
        Refund refund = service.create(createRequest);
        System.out.println(refund.toString());

        if (refund.getStatus() == Status.SUCCESS) {
            System.out.println("退款成功");
        }

        return result;
    }
}
